use nacos_rust_client::client::naming_client::NamingClient;
use std::sync::Arc;
use tonic::{Request, Response, Status};

use crate::rpc::proto::system_role::{
    role_server::Role, 
    GetListReq, 
    GetListRes
};

// 重新导出 RoleServer 供外部使用
pub use crate::rpc::proto::system_role::role_server::RoleServer;

#[derive(Clone)]
pub struct MyRole {
    naming_client: Arc<NamingClient>,
}

impl MyRole {
    pub fn new(naming_client: Arc<NamingClient>) -> Self {
        Self { naming_client }
    }
}

#[tonic::async_trait]
impl Role for MyRole {
    async fn get_list(&self, request: Request<GetListReq>) -> Result<Response<GetListRes>, Status> {
        println!("Role服务收到请求: {:?}", request.remote_addr());
        let req = request.into_inner();

        let reply = GetListRes {
            message: format!("角色列表: {}", req.name),
        };
        Ok(Response::new(reply))
    }
} 